<template>
	<div>
		<header class="customHeaderStyle" style="position:relative;">
			<div class="go-back" @click.stop="goback">
				<i></i>
				<i></i>
				<i></i>
			</div>
			<div class="headerCustomTitle">{{addFlag?"新增地址":"编辑地址"}}</div>
			<div class="aui-pull-right text-del" id="save" @click.stop="onSub">保存</div>
		</header>
	</div>
</template>

<script>
	 import {mapMutations,mapGetters,mapActions} from 'vuex';
	 import {Toast} from '../../../utils/toast'
	 export default {
        props: {
            dataList: {
                type: Array,
                default: () => []
            },
            addFlag: {
				type: Boolean,
                default:false
			},
			goback: {
				type:Function,
				defalt:()=>{}
			}
        },
        computed:{
        	...mapGetters('zx',[
        		"getNowAddress"
        	])
        },
        data () {
            return {
              
            }
        },
        methods: {
        	...mapActions('zx',[
        		"setAddressInfo"
        	]),
        	showMessage(msg) {
	            Toast({
	                message: msg,
	                duration: 1000,
	                type:'fail'
	            });
	        },
			onSub(){
				var params = {};
				
				params = this.$store.getters['zx/getNowAddress'];
				console.log(params,'params*********************************')

				if(!params.province || !params.city || !params.region ) {
	                this.showMessage('请输入收货地址')
	                return
	            }
	            if(!params.address) {
	                this.showMessage('请填写详细地址')
	                return
	            }
	            if(!params.receivername) {
	                this.showMessage('请填写收货人姓名')
	                return
	            }
	            if(!params.phone) {
	                this.showMessage('请填写联系号码')
	                return
	            } else {
	                let reg = new RegExp(/^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$/)
	                if(!reg.test(parseInt(params.phone))){
	                    this.showMessage('请填写正确的手机号')
	                    return
	                }
	            }
	            if(!params.label) {
	                this.showMessage('请选择地址标签')
	                return
	            }
				
				if(this.addFlag){
//					console.log("+-+-你的世界的嗡嗡嗡嗡嗡的我的地位-+-+",params);
					params.type = 'ADD';
					this.setAddressInfo(params);
					let id = this.$route.query.id;
					
					if(id){
						this.$router.push({path:'address',query:{id:2}});
					}else{
						this.$router.push('address');
					}
//					this.$router.push('address');
				}else{
					params.type = 'UPDATE';
					params.showToast = true;
//					console.log("+-+-+-你的世界哦批評加哦加哦解開了解開了看見了空間經理儘快瞭解+--++-+--+-+");
					this.setAddressInfo(params);
//					this.$router.push('address');
					let id = this.$route.query.id;
					
					if(id){
						this.$router.push({path:'address',query:{id:2}});
					}else{
						this.$router.push('address');
					}
				}
				
			}
        },
        created () {
   
        },
        mounted () {
			
        }
    }
</script>

<style scoped>
	.customHeaderStyle{
		position: relative;
		background: #fff;
		min-height: 3rem;
		border-bottom: 1px solid #eaeaea;
		color: #444;
		font-weight: 700;
		left: 0;
		top: 0;
		line-height: 2.25rem;
		/* z-index: 2; */
		width: 100%;
		font-size: .9rem;
		text-align: center;
		margin: 0;
		padding: 0;
	}
	.headerCustomTitle{
		overflow: hidden;
		right: 6rem;
		font-weight: 500;
		min-height: 2.25rem;
		position: absolute;
		margin: 0;
		text-align: left;
		white-space: nowrap;
		left: 3rem;
		width: auto;
		text-overflow: ellipsis;
		z-index: 2;
		font-size: 1.1rem;
		margin-top: .35rem;
		top: 1px;
	}
</style>